package com.data.modules.demo.biz.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.data.common.system.vo.DictModel;
import com.data.common.util.CmdUtils;
import com.data.modules.demo.biz.entity.Demo;
import com.data.modules.demo.biz.mapper.DemoMapper;
import com.data.modules.demo.biz.service.IDemoService;
import com.data.modules.system.service.ISysDictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: demo
 * @Author: data-boot
 * @Date:   2021-12-22
 * @Version: V1.0
 */
@Slf4j
@Service
public class DemoServiceImpl extends ServiceImpl<DemoMapper, Demo> implements IDemoService {

    @Autowired
    private ISysDictService iSysDictService;

    @Override
    public String resumeIsExist(String phone) {
        //必须分开写，不能有空格
        String[] cmds={"curl"
                ,"-s"
                ,"https://zl-gateway.junrunrenli.com/jrit-zl-biz/bizResume/resumeIsExist?phone="
                ,"-H","authority: zl-gateway.junrunrenli.com"
                ,"-H","accept: application/json, text/plain, */*"
                // ,"-H","accept-language: zh-CN,zh;q=0.9,en;q=0.8"
                ,"-H","origin: https://rpo2.junrunrenli.com"
                ,"-H","platform-type: 2"
                ,"-H","referer: https://rpo2.junrunrenli.com/"
                //,"-H","sec-ch-ua: \" Not A;Brand\";v=\"99\", \"Chromium\";v=\"102\", \"Google Chrome\";v=\"102\""
                ,"-H","sec-ch-ua-mobile: ?0"
                // ,"-H","sec-ch-ua-platform: \"Windows\""
                ,"-H","sec-fetch-dest: empty"
                ,"-H","sec-fetch-mode: cors"
                ,"-H","sec-fetch-site: same-site"
                ,"-H","tenantcode: SSO"
                ,"-H","user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36"
                ,"-H"
                //,"-H","authorization:Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImNiZGZiZmVmLWMzZjEtNDg0NS1hYWQ4LWMxZDkwYTI5YWFhMiJ9.eyJwcm9kdWN0IjoiaHJzYy1wcm8iLCJzdWIiOiJ6aGFuZ2ZlaSIsImF1ZCI6IlNTTyIsImV4cCI6MTY1NDc4NjMzNSwiaWF0IjoxNjU0NzQzMTM1LCJpc3MiOiJaTCJ9.Ix5sbaLrx2RDMaJuhSveF_jGOfnmZOitzwuzpYOla1YeNhM3Mf6dTteiovqa7TSr1eR_F6KrQbdgcrNsx045zpG9yVY8joa27Ry0YO81OVj-xKmMIrhqkNF09CogWnaOB9ruKAoM9DvDWdtP8JH-yYbn-eLt8E14zO8rAOTele3h-tSmNrk38q7JHjEF_kyzaRDQCsrPyCthCgHeHhL_pctk-wOmqtnxqC437_q-f-Eflmk-VAHH0t0rCegZXr606zWm7lddUj7o2rxwjfKviv3Nccix0Oi0wpgR1DJscNHC8a0fNqPWALAOesqJpEmDaihykxijeOKA4ZAC9R4t2A"
        }
                ;
        cmds[2]= cmds[2]+phone;

        String[] tempArray=new String[cmds.length+1];

        for (int i = 0; i < cmds.length; i++) {
            tempArray[i] = cmds[i];
        }
        tempArray[cmds.length] = "authorization:Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImNiZGZiZmVmLWMzZjEtNDg0NS1hYWQ4LWMxZDkwYTI5YWFhMiJ9.eyJwcm9kdWN0IjoiaHJzYy1wcm8iLCJzdWIiOiJ6aGFuZ2ZlaSIsImF1ZCI6IlNTTyIsImV4cCI6MTY1NDc4NjMzNSwiaWF0IjoxNjU0NzQzMTM1LCJpc3MiOiJaTCJ9.Ix5sbaLrx2RDMaJuhSveF_jGOfnmZOitzwuzpYOla1YeNhM3Mf6dTteiovqa7TSr1eR_F6KrQbdgcrNsx045zpG9yVY8joa27Ry0YO81OVj-xKmMIrhqkNF09CogWnaOB9ruKAoM9DvDWdtP8JH-yYbn-eLt8E14zO8rAOTele3h-tSmNrk38q7JHjEF_kyzaRDQCsrPyCthCgHeHhL_pctk-wOmqtnxqC437_q-f-Eflmk-VAHH0t0rCegZXr606zWm7lddUj7o2rxwjfKviv3Nccix0Oi0wpgR1DJscNHC8a0fNqPWALAOesqJpEmDaihykxijeOKA4ZAC9R4t2A";
        log.info("-----start-----");
        //String msg = CmdUtils.execCurl(tempArray);
        List<String> list = new ArrayList<>();
        list.add("curl");
        list.add("-s");

        DictModel switchModel = iSysDictService.querySysDictInfoByCode("sys_check_repeat");
        if(ObjectUtil.isNotEmpty(switchModel)){
            list.add(switchModel.getValue()+phone);
        }
        List<DictModel> switchModelList = iSysDictService.queryEnableDictItemsByCode("sys_check_repeat");

        for (DictModel dictModel : switchModelList) {
            list.add(dictModel.getDescription());
            list.add(dictModel.getText());
        }
        log.info("---cmdExce:{}", JSON.toJSON(list));
        String msg = CmdUtils.execCurlList(list);
        log.info("msg:{}",msg);
        log.info("-----end------");
        return msg;
    }


}
